home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / netBoot / sun4.md / RCS / start.s,v < prev   
Encoding:
Text File  |  1989-06-19  |  3.0 KB  |  135 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    mendel:1.1; strict;
  6. comment  @| @;
  7.  
  8.  
  9. 1.1
  10. date     89.06.19.14.11.16;  author mendel;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @!
  26. ! The following variable MUST be the first thing in this
  27. ! file, as its position marks the beginning of small data
  28. !
  29.     .seg    "data"
  30.     .global    _environ        ! first symbol in sdata        
  31. _environ:
  32.     .word    0
  33. !
  34. ! This variable is used in the DELAY macro.  5 is the right value for
  35. ! 68010's running 10MHz.  3 is the right value for 68020's running 16MHz
  36. ! with cache on.  (4x as fast at doing the delay loop.)  Other values
  37. ! should be empirically determined as needed.  Srt0.s sets this value
  38. ! based on the actual runtime environment encountered.
  39. !
  40. ! For a sunrise machine with no cache (16Mhz) the delay should be 4
  41. ! if the cache is on the delay can be 1
  42. !
  43. ! It's critical that the value be no SMALLER than required, e.g. the
  44. ! DELAY macro guarantees a MINIMUM delay, not a maximum.
  45. !
  46.     .seg    "data"
  47.     .global    _cpudelay
  48. _cpudelay:
  49.     .word    5            ! Multiplier for DELAY macro.
  50.  
  51.     .seg    "text"
  52.     .align    4
  53. !
  54. ! Startup code for standalone system
  55. !
  56. WINDOWSIZE = (16 * 4)
  57.  
  58.     .global    _end
  59.     .global    _edata
  60.     .global    _main
  61.     .global    __exit
  62.     .global    __exitto
  63.     .global    entry
  64. entry:
  65.     save    %sp, -WINDOWSIZE, %sp    ! get a new window, leave room for args
  66.     call    1f            ! get the current pc into o7
  67.     nop                ! (where entry is currently located)
  68. 1:
  69.     mov    %o7, %o0        ! save for later
  70.     sub    %o0, 4, %o0        ! point to first byte of prog
  71.     set    entry+4,%o6        ! address of call instruction - above 
  72.     cmp    %o6, %o7        ! are they the same
  73.     be    start
  74.     nop
  75.     set    _edata+4, %o2        ! end of program, inclusive, except bss
  76.     set    entry, %o1        ! beginning of program
  77.     sub    %o2, %o1, %o2        ! size of program
  78.     !
  79.     ! check that the following copy won't write on itself
  80.     !
  81.     !add    %o7,%o2,%o5
  82.     !cmp    %o5,%o0    
  83.     !bg    cantreloc
  84.     !nop
  85.     !
  86.     ! copy program where it belongs
  87.     !
  88. 2:
  89.     ld    [%o0], %o3        ! read a word
  90.     inc    4, %o0            ! point to next src word
  91.     st    %o3, [%o1]        ! write a word
  92.     deccc    4, %o2            ! check if done
  93.     bge    2b            ! if not loop
  94.     inc    4, %o1            ! delay slot, point to next dest word
  95.     
  96.     set    start, %g1        ! now that it is relocated, jump to it
  97.     jmp    %g1
  98.     nop
  99.     ! program is now relocated
  100. start:
  101.     ! we should turn on cache at least by now
  102.     set    _end+4, %o2        ! end of bss
  103.     set    _edata, %o0        ! beginning of bss
  104.     sub    %o2, %o0, %o2        ! size of bss
  105.     ! zero the bss
  106. 1:
  107.     deccc    %o2            ! loop to zero bss
  108.     clr    [%o0]
  109.     bnz    1b
  110.     inc    4, %o0
  111.  
  112.     ! general startup code
  113.     set    (_environ+0x1000), %g7    ! 1st global register (etext + 4K)
  114.     set    0x2000, %g6        ! 8k
  115.     add    %g7, %g6, %g6        ! 2nd global register (1st global + 8K)
  116.     ld    [%sp + WINDOWSIZE], %o0    ! argc
  117.     add    %sp, WINDOWSIZE + 4, %o1! argv
  118.     sll    %o0, 2, %o2        ! argc * sizeof (int)
  119.     add    %o2, 4, %o2        ! skip 0 at end of arg ptrs
  120.     add    %o1, %o2, %o2        ! environ ptr
  121.     call    _main
  122.     st    %o2, [%g7 + -0x1000]    ! store 1st word of sdata %ad(_environ)
  123.     nop
  124.     call    _exit            ! exit(0)
  125.     mov    0, %o0            ! delay slot
  126. __exit:
  127.     ret                ! ret to prom
  128.     restore
  129.  
  130. __exitto:
  131.     mov    %o0, %o7        ! will return to address in o7+8
  132.     ret                ! on caller stack
  133.     restore
  134. @
  135.